﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SystemDiagramNew
{
	public partial class LoadingForm : Form, IProceeding
	{
		public LoadingForm()
		{
			this.InitializeComponent();
			this.loadingCircle1.Active = true;
		}

		public void Proceeding()
		{
			int tickCount = Environment.TickCount;
			if (tickCount - this.prevTick < 100)
			{
				return;
			}
			Application.DoEvents();
			this.prevTick = tickCount;
		}

		public void Report(int progress, string message)
		{
			this.Proceeding();
			if (!string.IsNullOrEmpty(message))
			{
				this.tbMsg.Text = message;
			}
		}

		public void Show(IntPtr ownerHandle)
		{
			this.prevTick = Environment.TickCount;
			System.Windows.Forms.Control control = System.Windows.Forms.Control.FromHandle(ownerHandle);
			IWin32Window owner;
			if (control == null)
			{
				owner = new WindowWrapper(ownerHandle);
				base.StartPosition = FormStartPosition.CenterScreen;
			}
			else
			{
				owner = control;
				base.StartPosition = FormStartPosition.CenterParent;
			}
			base.Show(owner);
		}

		public void ShowDialog(Action action)
		{
            //Action <>9__1;
            //base.Shown += delegate(object _, EventArgs args)
            //{
            //    TaskFactory factory = Task.Factory;
            //    Action action2;
            //    if ((action2 = <>9__1) == null)
            //    {
            //        action2 = (<>9__1 = delegate
            //        {
            //            action();
            //            this.Close();
            //        });
            //    }
            //    factory.StartNew(action2);
            //};
			base.ShowDialog();
		}

		private int prevTick;
	}
}
